#include"tim5.h"

void tim5_init(void)
{
    //1.时钟配置
    RCC->APB1ENR|=RCC_APB1ENR_TIM5EN;
    RCC->APB2ENR|=RCC_APB2ENR_IOPAEN;

    //引脚配置 PA0 TIM5 CH1 复用推挽输出 CNF 10 MODE11
    GPIOA->CRL|=GPIO_CRL_CNF0_1;
    GPIOA->CRL&=~GPIO_CRL_CNF0_0;
    GPIOA->CRL|=GPIO_CRL_MODE0;

    TIM5->PSC=7199;
    TIM5->ARR=99;
    //向上计数
    TIM5->CR1&=~TIM_CR1_DIR;

    //开始配置输出捕获通道一
    TIM5->CCMR1&=~TIM_CCMR1_CC1S;
    TIM5->CCMR1&=~TIM_CCMR1_OC1M_0;
    TIM5->CCMR1|=TIM_CCMR1_OC1M_2;
    TIM5->CCMR1|=TIM_CCMR1_OC1M_1;

    //
    TIM5->CCR1=50;
    TIM5->CCER&=~TIM_CCER_CC1P;//极性
    TIM5->CCER|=TIM_CCER_CC1E; //使能
    
}

void tim5_start(void)
{
    TIM5->CR1|=TIM_CR1_CEN;
}

void tim5_stop(void)
{
    TIM5->CR1&=~TIM_CR1_CEN;
}

void tim5_duty(uint8_t duty)
{
    TIM5->CCR1=duty;
}